// 0_core_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream> 
#include <vector> 

void test_string()
{
	{
		DString str0;
		_check( str0 == 0);
		//std::cout<< (const char*)str0<< std::endl;
		DString str1("test str abcdef.");
		std::cout<< (const char*)str1<< std::endl;
		DString str2 = "test value2 str ghijk.";
		std::cout<< (const char*)str2<< std::endl;

		str0 = str1;
		str0 = "new value";
		std::cout<< "str0 = \"new value\""<< std::endl;
		std::cout<< "str0 = "<< str0 << std::endl;
		std::cout<< "str1 = "<< str1 << std::endl;
		
	}


	{
		DString test;
		test += "test";
		std::cout<< test<< std::endl;
		std::cout<< "test[0] = "<<test[0]<< std::endl;
		std::cout<< "test[1] = "<<test[1]<< std::endl;
		std::cout<< "test[2] = "<<test[2]<< std::endl;
		std::cout<< "test[3] = "<<test[3]<< std::endl;
	}

	{
		DString test;
		test.FormatSelf("fmt: int %d, float %f, str %s", 100, 0.5f, "string val");
		std::cout<< test<< std::endl;

		DString fmt =  DString::Format("fmt: int %d, float %f, str %s", 100, 0.5f, "string val");
		std::cout<< fmt<< std::endl;
	}

	
	{
		DString test;
		test += "1234567 890";
		std::cout<< test.Cmp( "1234567 890")<< std::endl;
		test = "abc";
		std::cout<< test.Cmp( "ABC")<< std::endl;
		std::cout<< test.ICmp( "ABC")<< std::endl;
	}

	{
		DString test = "1234567890";
		DString v1 = test.Sub( 0, 3);
		std::cout<< v1<< std::endl;
		DString v2 = test.Sub( 3, 6);
		std::cout<< v2<< std::endl;
		DString v3 = test.Sub( 6, 9);
		std::cout<< v3<< std::endl;


		s32_t pos = 0;
		DString v4 = test.Split( "31590", pos);
		while( v4 )
		{
			std::cout<< v4<< std::endl;

			v4 = test.Split( "31509", pos);
		}

	}

	{
		DString test = "1234567890";
		std::cout<< "find \"312\" pos = " <<test.Find("312")<< std::endl;;
		std::cout<< "FindFristOf \"369\" pos = " <<test.FindFristOf("369")<< std::endl;;
		std::cout<< "FindFristOf DString() pos = " <<DString().FindFristOf("369")<< std::endl;;
	}

	{
		DString test = "1234567890";
		test.Replace( "456", "ABC");
		std::cout<< test<< std::endl;
	}

	{
		DString test = "abcdef ABCDEF";
		DString val0 = test;
		val0.Upper();
		std::cout<< val0<< std::endl;
		
		val0 = test;
		val0.Lower();
		std::cout<< val0<< std::endl;
	}


	{
		DString test9 = "999999";
		DString test = "abcdef ABCDEF ";
		test += test9;
		test.Cat( test);
		test.Cat( "abcdef");
		test.Cat( "  ");
		test.Cat( test);
		test.Cat( test9);
		std::cout<< test<< std::endl;
	}

	{
		DString test9 = "999999";
		std::cout<< test9<< std::endl;
		
		DString test = test9;
		std::cout<< test<< std::endl;
		
		test = '6';
		std::cout<< test<< std::endl;
		
		test += '6';
		std::cout<< test<< std::endl;
		
		test += DString(" 9023f");
		std::cout<< test<< std::endl;
		
		test += "asdfo";
		std::cout<< test<< std::endl;
	}


	{
		DString a_test = "abcd";
		DString a_test2 = "abcd2";
		char* c_test = "abcd";
		char* c_test2 = "abcd2";

		std::cout<< (a_test == a_test2)<< std::endl;
		std::cout<< (a_test != a_test2)<< std::endl;
		std::cout<< (a_test == c_test)<< std::endl;
		std::cout<< (a_test != c_test2)<< std::endl;

		std::cout<< (c_test == a_test) << std::endl;
		std::cout<< (c_test2 == a_test) << std::endl;


		std::cout<< (c_test + a_test) << std::endl;
		std::cout<< (a_test + a_test) << std::endl;
		std::cout<< (a_test + 'a') << std::endl;
		std::cout<< (a_test + "lpstr") << std::endl;

	}
}

void test_vector()
{
	std::cout<< "test_vector()"<< std::endl;

	TArray<DString> ary(6);
	ary[0] = "1";
	ary[1] = "2";
	ary[1] += ary[1];

	ary[2] = "2";
	ary[2] += ary[1] + ary[0];
	ary[3] = "3";
	ary[4] = "4";
	ary[5] = "5";
	for( s32_t i = 0 ; i < 6; ++i)
	{
		std::cout<< ary[i]<< std::endl;
	}

	std::cout<< ary.Num()<< std::endl;

	s32_t outIndex = null_index;
	std::cout<< ary.Find( "4", outIndex)<< std::endl;
	std::cout<< outIndex<< std::endl;
	std::cout<< ary.FindIndex( "4")<<std::endl;
	std::cout<< ary.Add( "last value")<< std::endl;
	std::cout<< ary.Last()<< std::endl;
	std::cout<< ary.Num()<< std::endl;
	std::cout<< "ary.AddUnique( \"last value\")  " <<  ary.AddUnique( "last value")<< std::endl;
	std::cout<< ary.Num()<< std::endl;
	std::cout<< ary.Pop()<< std::endl;
	std::cout<< ary.Num()<< std::endl;
	std::cout<< "-------------"<< std::endl;
	std::cout<< ary.Remove("4")<< std::endl;
	std::cout<< ary.Num()<< std::endl;
	std::cout<< ary.FindIndex( "4")<<std::endl;

	TArray<DString> aryCpy = ary;

	std::cout<< "-------------"<< std::endl;
	std::cout<< ary.Num() <<" "<< ary.NumBuf()<< std::endl;
	ary.Shrink();
	std::cout<< ary.Num() <<" "<< ary.NumBuf()<< std::endl;
	ary.Clear();
	std::cout<< ary.Num() <<" "<< ary.NumBuf()<< std::endl;


	std::cout<< "-------------"<< std::endl;
	std::cout<< "-------------"<< std::endl;
	std::cout<< aryCpy.Num() <<" "<< aryCpy.NumBuf()<< std::endl;
	{
		TArray<DString>::Iterator it( aryCpy);

		while( it)
		{
			std::cout<< it.CurrIndex()<< ": "<< it.Current() << std::endl;
			it.Next();
		}

	}
	std::cout<< "-------------"<< std::endl;

	{
		TArray<DString>::Iterator it2( aryCpy);
		for( s32_t i = 0; i <2;++i)
		{
			it2.Next();
		}
		std::cout<< it2.CurrIndex()<< ": "<< it2.Current() << std::endl;
		it2.RemoveCurrent();
		std::cout<< it2.CurrIndex()<< ": "<< it2.Current() << std::endl;
	}
	std::cout<< "-------------"<< std::endl;

	{
		TArray<DString>::Iterator it( aryCpy);

		while( it)
		{
			std::cout<< it.CurrIndex()<< ": "<< it.Current() << std::endl;
			it.Next();
		}
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	CoreInit();

	test_string();
	test_vector();

	CoreShutdown();

	char in;
	std::cin>>in;
	return 0;
}
